/*
 * init.h
 *
 *  Created on: 29/gen/2014
 *      Author: massimo
 */

#ifndef INIT_H_
#define INIT_H_

#include <stdio.h>

typedef struct{
	unsigned int sec;
} __time;

typedef struct{
	unsigned char 	cmd;
	unsigned char 	rep;
	unsigned int 	dato;
	unsigned char 	stato;
} __statMsg;

typedef struct{
	int 			time;
	unsigned int 	line;			/// linea attule
	unsigned int 	stLine;			/// linea da cui parte la sequenza
	unsigned int 	endLine;		/// linea di stop della sequenza
	unsigned char 	stato;
} __seq;

typedef struct{
	unsigned char sec;
	unsigned char min;
	unsigned char hour;
	unsigned char day;
	unsigned char month;
	unsigned char year;
	unsigned char minF;
	unsigned char hourF;
} __timeON;


int fputc(int _c, register FILE *_fp);
int fputs(const char *_ptr, register FILE *_fp);

unsigned long int setDCO_XTAL(unsigned long int mhz);
unsigned long int setDCO(unsigned long int mhz);
/// fo e durata dell'intervallo in ms
void initTIMER(unsigned long FDCO, unsigned int tick);
void initRTC(void);
void initPort();
void initUART1(unsigned long bitRate, unsigned long fdco);
void initUART0(unsigned long bitRate, unsigned long fdco);
unsigned int impostaTemp(unsigned int minuti);
void parseMessage(__statMsg *stM, __seq*);
void tokCpm(int cont, char *tok, __statMsg *, __seq*);

unsigned char eseguiComando(__statMsg *, __seq *, unsigned char* flag);
void avanzamento(__seq *seq);
void start(__seq *seq);
void stop();

unsigned char loadFromFlash(__statMsg *stMess, __seq *seq);
void erase_Seg(char * flashBankPtr);
unsigned char saveToBankFlash(__statMsg *stMess, __seq *seq, char * flashBankPtr);

#define			BUFF_DIM				128
#define			ON						128
#define			OFF						129
#define			MAX_LINE				20
#define			ENDED					128
#define			NONE					0
#define			TEMPO					1
#define			AVVIO					2
#define			STOP					3
#define			IMP_LINEA				4
#define			IMP_LINEA_FINALE		5
#define			RIPETI					6
#define 		STATO_OK				0
#define			NOT_VALID 				1
#define 		VALID					0

#define			ERR_STATUS				199
#define			LINEA_STATUS			198
#define			SET_LINEA				197
#define			HELP_STATUS				196
#define			RELEASE_STATUS			195

#endif /* INIT_H_ */
